package com.loveprogrammer.eternity.skill.support.skills.thunder;

import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.enums.AttackTypeEnum;
import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.model.attack.AttackEntity;
import com.loveprogrammer.eternity.model.attack.AttackResult;
import com.loveprogrammer.eternity.skill.support.skills.AbstractSkill;
import com.loveprogrammer.eternity.skill.support.states.DazeState;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @version 1.0.0
 * @description: 惊雷斩
 * @author: eric
 * @date: 2023-10-08 16:53
 **/
public class SkillThunderChop extends AbstractSkill {

    public SkillThunderChop(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    protected Tuple<String, List<Character>> skillLaunch(Character character,
                                                         List<? extends Character> attack,
                                                         List<? extends Character> defences) {
        Tuple<String, List<Character>> tuple = new Tuple();
        // 按照血量排序，攻击血量最低的 不吃嘲讽
        Character defence = findSingleAttacker(defences,false);

        StringBuilder builder = new StringBuilder();
        builder.append(character.getName()).append("(").append(character.getCurrentHp()).append("/")
                .append(character.getHpMax()).append(")").append(" 使用技能[")
                .append(getName()).append(" ").append(getLevel()).append("级】攻击了 ").append(defence.getName());
        int power = getHarm(character);

        // 暴击检测 提升200%的伤害 几率 技巧 + 500 / 技巧 + 6000
        boolean crit = critCheck(character);
        if(crit) {
            power = critPower(power);;
        }
        //
        AttackResult attackResult = defence.defence(new AttackEntity(this, power, AttackTypeEnum.THUNDER));
        computeHarm(builder,crit,defence,attackResult, character, attack, defences);

        int percents = getSecondHarm(character);
        // 几率进入眩晕状态
        if(new Random().nextInt(100) < percents) {
            DazeState dazeState = new DazeState(defence, defences, 5000);
            // 眩晕就是等到下次攻击前等待一定时间
            boolean state = defence.acquireState(dazeState, 99);
            // 施展成功 5秒钟
            if (state) {
                builder.append(defence.getName()).append("进入眩晕状态;\n");
            } else {
                builder.append(defence.getName()).append("眩晕无效;\n");
            }
        }

        List<Character> value = new ArrayList<>();
        value.add(defence);
        tuple.setKey(builder.toString());
        tuple.setValue(value);
        return tuple;
    }

    @Override
    protected int computeHarm(Character character) {
        return (int) (character.getStrength() * 2.5 * ((getBaseHarm() + getLevel() * 2) / 100));
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 30;
    }

    @Override
    public boolean check(Character character) {
        if(restInterval() <= 0) {
            return true;
        }
        return false;
    }

    @Override
    public int opportunityPassive() {
        return 0;
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每5 升一级
        if(characterLevel % 5 == 0){
            return true;
        }
        return false;
    }

    @Override
    public int defaultHarm() {
        setBaseHarm(120);
        return 120;
    }
}
